import React, {Component} from 'react';
import { Image,View, Text,StyleSheet,Dimensions,ScrollView,WebView } from 'react-native';
import {WhiteSpace,Flex,ActivityIndicator,List,Toast,Carousel,Tabs} from 'antd-mobile-rn';
import Layout from '../components/Layout';
import { post } from '../utils/request';
import SyList from '../components/SyList';
import config from '../config';
import tool from '../utils/tool';

export default class VideoDetail extends Component {
    //构造函数
    constructor(props) {
        super(props);
        this.state = {
            loading:false,
            id: this.props.navigation.state.params.id,
            title:"",
            urls:"",
            imgurl:"",
            webviewHeight:0,
        };
    }
    //组件加载
    componentDidMount() {
        post("/openapi/getInfo/",{
            id:this.state.id
        },(r)=>{
            //document.title=r.data.title +"-视频-"+config.sitename;
            this.setState({
                title:r.data.title,
                urls:r.data.urls,
                imgurl:r.data.imgurl,
            });
            console.log("网址:"+this.state.urls);
        },(e)=>{
            Toast.fail(e.message,3);
        },(s)=>{
            this.setState({loading:s});
        });
    }

    //组件卸载
    componentWillUnmount() {

    }
    //属性改变
    componentWillReceiveProps(nextProps) {
    }

    openVideo(url)
    {
        //window.location.href=url;
    }

    render() {
        return (
            <View style={{flex:1}}>
                <WebView 
                scrollEnabled={false} 
                //source={{html: `<!DOCTYPE html><html><body>等待跳转页面!<script>window.onload=function(){ window.open('${this.state.urls}');}</script></body></html>`, baseUrl: ''}}
                source={{uri:this.state.urls}}
                style={{}} 
                automaticallyAdjustContentInsets={true}
                javaScriptEnabled={true}
                domStorageEnabled={true}
                allowsInlineMediaPlayback={true}
                />
                <ActivityIndicator
                    toast
                    size="large"
                    text="数据加载中..."
                    animating={this.state.loading}
                />
            </View>
        );
    }
}
